#include "applyfriend.h"
#include "findsuccessdlg.h"
#include "ui_findsuccessdlg.h"

#include <QDir>
#include <QDebug>
FindSuccessDlg::FindSuccessDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FindSuccessDlg)
{
    ui->setupUi(this);
    // 设置对话框标题
    setWindowTitle("添加");
    // 隐藏对话框标题栏
    setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
    // 获取当前应用程序的路径
    QString app_path = QCoreApplication::applicationDirPath();
    QString pix_path = QDir::toNativeSeparators(app_path +
                             QDir::separator() + "static"+QDir::separator()+"head_1.jpg");
    QPixmap head_pix(pix_path);
    head_pix = head_pix.scaled(ui->headLb->size(),
            Qt::KeepAspectRatio, Qt::SmoothTransformation);
    ui->headLb->setPixmap(head_pix);
    ui->addFriend_btn->SetState("normal","hover","press");
    this->setModal(true);

    connect(ui->addFriend_btn,&QPushButton::clicked,this,[=](){
        emit SlotAddFriend();
    });
}

FindSuccessDlg::~FindSuccessDlg()
{
    qDebug()<<"FindSuccessDlg destruct";
    delete ui;
}

void FindSuccessDlg::SetSearchInfo(std::shared_ptr<SearchInfo> si)
{
    ui->nameLb->setText(si->_name);
    _si = si;
}

void FindSuccessDlg::SlotAddFriend()
{
    //弹出加好友界面
    qDebug() << "-2";
    try {
        auto applyFriend = new ApplyFriend();
        applyFriend->SetSearchInfo(_si);
        applyFriend->setModal(true);
        this->hide();
        applyFriend->show();
    } catch (const std::exception &e) {
        qDebug() << "捕获到异常：" << e.what();
    }

}
